package com.dongbo.recorder.screenrecord.utils;

import android.text.TextUtils;

import java.util.regex.Pattern;

public class TextValidator {
    /**
     * 正则表达式:验证手机号
     */
    public static final String REGEX_MOBILE = "^1\\d{10}$";
    public static final String REGEX_EMAIL = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
    public static final String REGEX_PASSWORD = "^[a-zA-Z0-9_]{6,18}$";
    public static final String REGEX_VERIFY_CODE = "\\d{4}";

    /**
     * 检验字符串是否达到指定长度
     */
    public static boolean isVerifyCode(String text) {
        if (TextUtils.isEmpty(text)) {
            return false;
        }
        return Pattern.matches(REGEX_VERIFY_CODE, text);
    }

    public static boolean isMobilePhone(String text) {
        if (TextUtils.isEmpty(text)) {
            return false;
        }
        return Pattern.matches(REGEX_MOBILE, text);
    }

    public static boolean isPassword(String text) {
        if (TextUtils.isEmpty(text)) {
            return false;
        }
        return Pattern.matches(REGEX_PASSWORD, text);
    }

    public static boolean isEmail(String text) {
        if (TextUtils.isEmpty(text)) {
            return false;
        }
        return Pattern.matches(REGEX_EMAIL, text);
    }
}
